package com.kotlin.hxh.ui.fragment.first.child

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.kotlin.hxh.R
import com.kotlin.hxh.base.BaseBackFragment
import com.kotlin.hxh.entity.Article
import com.kotlin.hxh.ui.fragment.CycleFragment
import kotlinx.android.synthetic.main.content_detail.*
import kotlinx.android.synthetic.main.zhihu_fragment_first_detail.*

/**
 * @author huxh
 * @date 2018/12/17.
 */
class FirstDetailFragment : BaseBackFragment() {
    private var mArticle: Article? = null

    companion object {
        private val ARG_ITEM = "arg_item"

        @JvmStatic
        fun newInstance(article: Article): FirstDetailFragment {
            val fragment = FirstDetailFragment()
            val arsg = Bundle()
            arsg.putParcelable(ARG_ITEM, article)
            fragment.arguments = arsg
            return fragment
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mArticle = arguments?.getParcelable<Article>(ARG_ITEM)
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        return inflater.inflate(R.layout.zhihu_fragment_first_detail, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        initView()
    }

    private fun initView() {
        toolbar.title = ""
        initToolbarNav(toolbar)
        img_detail.setImageResource(mArticle!!.imgRes)
        tv_content.text = mArticle!!.title
        fab.setOnClickListener { start(CycleFragment.newInstance(1)) }
    }
}